# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=asio
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.32.0
pkgrel=1
pkgdesc='Cross-platform C++ library for ASynchronous network I/O (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://think-async.com/Asio/'
msys2_repository_url="https://github.com/chriskohlhoff/asio"
license=('spdx:BSL-1.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             #"${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-openssl")
source=("https://github.com/chriskohlhoff/asio/archive/asio-${pkgver//./-}.tar.gz")
sha256sums=('f1b94b80eeb00bb63a3c8cef5047d4e409df4d8a3fe502305976965827d95672')

prepare() {
  cd "${srcdir}"/${_realname}-${_realname}-${pkgver//./-}/asio

  autoreconf -fiv
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  CPPFLAGS+=" -D_WIN32_WINNT=0x601" \
  ../${_realname}-${_realname}-${pkgver//./-}/asio/configure \
    --prefix=${MINGW_PREFIX} \
    --with-boost=no \
    --with-openssl=yes

  # Allow it to fail
  make || true
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make check || true
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  # make DESTDIR="${pkgdir}" install
  make DESTDIR="${pkgdir}" install-data-am
  make DESTDIR="${pkgdir}" -C include install-data-am

  install -Dm 644 "${srcdir}"/${_realname}-${_realname}-${pkgver//./-}/asio/COPYING -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  install -Dm 644 "${srcdir}"/${_realname}-${_realname}-${pkgver//./-}/asio/LICENSE_1_0.txt -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
}
